using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XCharts;
using System;
using KFGame;
public class KFStatitcsLog : MonoBehaviour
{
    // Start is called before the first frame update
    public string logname = "coin";

    //统计7天
    public int daysCount = 7;

    //统计12个月
    public int monthCount = 12;

    //季度
    public int quarterCount = 4;

    //统计年
    public int yearCount = 4;

    void Start()
    {
        setDatas();
    }

    public void setDatas()
    {
        var charts = transform.GetComponentsInChildren<BaseChart>();
        for (int a = 0; a < charts.Length; a++)
        {
            if (a == 0)
            {
                setDays(charts[a]);
                continue;
            }
            if (a == 1)
            {
                setMonths(charts[a]);
                continue;
            }
            if (a == 2)
            {
                setYear(charts[a]);
                continue;
            }
        }

    }
    public void setYear(BaseChart chart)
    {
        int year = DateTime.Now.Year;
        for (int a = 0; a < 6; a++)
        {
            YearLog dlog = new YearLog(logname);
            dlog.load(-a);
            if (dlog.listDatas.Count == 0)
                chart.AddData(0, 0);
            else
                chart.AddData(0, (float)dlog.listDatas[0]);

            CoordinateChart cchart = chart as CoordinateChart;
            if (cchart == null) continue;

            cchart.AddXAxisData((year - a) + "年");


        }
    }
    public void setMonths(BaseChart chart)
    {
        for (int a = 0; a < 12; a++)
        {
            MonthLog log = new MonthLog(logname);
            log.setMonth(a + 1);
            log.load();

            if (log.listDatas.Count == 0)
                chart.AddData(0, 0);
            else
                chart.AddData(0, (float)log.listDatas[0]);

            CoordinateChart cchart = chart as CoordinateChart;
            if (cchart == null) continue;
            cchart.AddXAxisData((a + 1) + "月");
        }

    }

    public void setDays(BaseChart chart)
    {
        for (int i = 0; i < daysCount; i++)
        {
            DaysLog dlog = new DaysLog(logname);
            dlog.load(-i);
            if (dlog.listDatas.Count == 0)
                chart.AddData(0, 0);
            else
                chart.AddData(0, (float)dlog.listDatas[0]);

            CoordinateChart cchart = chart as CoordinateChart;
            if (cchart == null) continue;

            if (i == 0)
            {
                cchart.AddXAxisData("今天");
                continue;
            }
            if (i == 1)
            {
                cchart.AddXAxisData("昨天");
                continue;
            }
            if (i == 2)
            {
                cchart.AddXAxisData("前天");
                continue;
            }

            cchart.AddXAxisData(i + "天前");
        }
    }

    // Update is called once per frame
    void Update()
    {
    }
}
